package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.DoctorDao;
import com.qfedu.stussm.dao.EquipmentDao;
import com.qfedu.stussm.entity.Doctor;
import com.qfedu.stussm.entity.Equipment;
import com.qfedu.stussm.service.intf.DoctorService;
import com.qfedu.stussm.service.intf.EquipmentService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentDao equipmentDao;

    @Override
    public R add(Equipment equipment) {
        if (equipmentDao.add(equipment) >0) {
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBeanVo selectAll(String keyword, int page, int limit) {
        if(keyword != null && keyword.length() > 0){
            keyword="%"+keyword+"%";
        }else{
            keyword = null;
        }
        PageHelper.startPage(page, limit);
        PageInfo<Equipment> pageInfo = new PageInfo<>(equipmentDao.queryAll(keyword));
        return new PageBeanVo(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public R update(Equipment equipment) {
        if (equipmentDao.update(equipment) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @Override
    public R delbyids(List<Integer> ids) {
        if (equipmentDao.delbyids(ids)>0){
            return R.ok();
        } else {
            return R.fail();
        }
    }
}
